package com.rightrule.rule.compile;

import com.rightrule.rule.constans.ScriptTypeEnum;
import groovy.lang.GroovyObject;
import lombok.Data;

import java.util.Map;

/**
 * Groovy编译实例
 */
@Data
public class GroovyCompiledInstance implements CompilableInstance<GroovyObject> {

    private final GroovyObject groovyObject;

    public GroovyCompiledInstance(GroovyObject groovyObject) {
        this.groovyObject = groovyObject;
    }

    @Override
    public ScriptTypeEnum getScriptType() {
        return ScriptTypeEnum.Groovy;
    }

    @Override
    public Object execute(Map<String, Object> variableMap) {
        return groovyObject.invokeMethod("mainCompute", variableMap);
    }

    @Override
    public GroovyObject getCompiledInstance() {
        return getGroovyObject();
    }
}
